package org.apache.poi.hwpf.converter;

import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.w3c.dom.Element;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/**
 * User: zigang.wang
 * Date: 12-8-3
 * Time: 下午3:47
 */
public class MyPicturesManager implements PicturesManager{
    String baseImageUrl = "d:/doc/image";
    @Override
    public String savePicture(byte[] content, PictureType pictureType, String suggestedName, float widthInches, float heightInches) {
        FileOutputStream out = null;
        String imageUrl = baseImageUrl.concat(File.separator).concat(suggestedName);
        try {
            out = new FileOutputStream(new File(baseImageUrl.concat(File.separator).concat(suggestedName)));
            IOUtils.copy(new ByteArrayInputStream(content), out);
            return imageUrl;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
